# The following KEYID numbers are currently unused:
#
# 199, 204, 228-237, 239, 241-255, 258-303, 316-351,
# 416-437, 439-447, 452-509, 512-529, 531-626, 628-UP.
#
# PLEASE NOTE: If you add any buttons PLEASE update this list to assist
# others in maintaining this file.

KEYIDS = {
	"KEY_RESERVED": 0,
	"KEY_ESC": 1,
	"KEY_1": 2,
	"KEY_2": 3,
	"KEY_3": 4,
	"KEY_4": 5,
	"KEY_5": 6,
	"KEY_6": 7,
	"KEY_7": 8,
	"KEY_8": 9,
	"KEY_9": 10,
	"KEY_0": 11,
	"KEY_MINUS": 12,
	"KEY_EQUAL": 13,
	"KEY_BACKSPACE": 14,
	"KEY_TAB": 15,
	"KEY_Q": 16,
	"KEY_W": 17,
	"KEY_E": 18,
	"KEY_R": 19,
	"KEY_T": 20,
	"KEY_Y": 21,
	"KEY_U": 22,
	"KEY_I": 23,
	"KEY_O": 24,
	"KEY_P": 25,
	"KEY_LEFTBRACE": 26,
	"KEY_RIGHTBRACE": 27,
	"KEY_ENTER": 28,
	"KEY_LEFTCTRL": 29,
	"KEY_A": 30,
	"KEY_S": 31,
	"KEY_D": 32,
	"KEY_F": 33,
	"KEY_G": 34,
	"KEY_H": 35,
	"KEY_J": 36,
	"KEY_K": 37,
	"KEY_L": 38,
	"KEY_SEMICOLON": 39,
	"KEY_APOSTROPHE": 40,
	"KEY_GRAVE": 41,
	"KEY_LEFTSHIFT": 42,
	"KEY_BACKSLASH": 43,
	"KEY_Z": 44,
	"KEY_X": 45,
	"KEY_C": 46,
	"KEY_V": 47,
	"KEY_B": 48,
	"KEY_N": 49,
	"KEY_M": 50,
	"KEY_COMMA": 51,
	"KEY_DOT": 52,
	"KEY_SLASH": 53,
	"KEY_RIGHTSHIFT": 54,
	"KEY_KPASTERISK": 55,
	"KEY_LEFTALT": 56,
	"KEY_SPACE": 57,
	"KEY_CAPSLOCK": 58,
	"KEY_F1": 59,
	"KEY_F2": 60,
	"KEY_F3": 61,
	"KEY_F4": 62,
	"KEY_F5": 63,
	"KEY_F6": 64,
	"KEY_F7": 65,
	"KEY_F8": 66,
	"KEY_F9": 67,
	"KEY_F10": 68,
	"KEY_NUMLOCK": 69,
	"KEY_SCROLLLOCK": 70,
	"KEY_KP7": 71,
	"KEY_KP8": 72,
	"KEY_KP9": 73,
	"KEY_KPMINUS": 74,
	"KEY_KP4": 75,
	"KEY_KP5": 76,
	"KEY_KP6": 77,
	"KEY_KPPLUS": 78,
	"KEY_KP1": 79,
	"KEY_KP2": 80,
	"KEY_KP3": 81,
	"KEY_KP0": 82,
	"KEY_KPDOT": 83,
	"KEY_103RD": 84,
	"KEY_F13": 85,
	"KEY_102ND": 86,
	"KEY_F11": 87,
	"KEY_F12": 88,
	"KEY_F14": 89,
	"KEY_F15": 90,
	"KEY_F16": 91,
	"KEY_F17": 92,
	"KEY_F18": 93,
	"KEY_F19": 94,
	"KEY_F20": 95,
	"KEY_KPENTER": 96,
	"KEY_RIGHTCTRL": 97,
	"KEY_KPSLASH": 98,
	"KEY_SYSRQ": 99,
	"KEY_RIGHTALT": 100,
	"KEY_LINEFEED": 101,
	"KEY_HOME": 102,
	"KEY_UP": 103,
	"KEY_PAGEUP": 104,
	"KEY_LEFT": 105,
	"KEY_RIGHT": 106,
	"KEY_END": 107,
	"KEY_DOWN": 108,
	"KEY_PAGEDOWN": 109,
	"KEY_INSERT": 110,
	"KEY_DELETE": 111,
	"KEY_MACRO": 112,
	"KEY_MUTE": 113,
	"KEY_VOLUMEDOWN": 114,
	"KEY_VOLUMEUP": 115,
	"KEY_POWER": 116,
	"KEY_KPEQUAL": 117,
	"KEY_KPPLUSMINUS": 118,
	"KEY_PAUSE": 119,
	"KEY_F21": 120,
	"KEY_F22": 121,
	"KEY_F23": 122,
	"KEY_F24": 123,
	"KEY_KPCOMMA": 124,
	"KEY_LEFTMETA": 125,
	"KEY_RIGHTMETA": 126,
	"KEY_COMPOSE": 127,
	"KEY_STOP": 128,
	"KEY_AGAIN": 129,
	"KEY_PROPS": 130,
	"KEY_UNDO": 131,
	"KEY_FRONT": 132,
	"KEY_COPY": 133,
	"KEY_OPEN": 134,
	"KEY_PASTE": 135,
	"KEY_FIND": 136,
	"KEY_CUT": 137,
	"KEY_HELP": 138,
	"KEY_MENU": 139,
	"KEY_CALC": 140,
	"KEY_SETUP": 141,
	"KEY_SLEEP": 142,
	"KEY_WAKEUP": 143,
	"KEY_FILE": 144,
	"KEY_SENDFILE": 145,
	"KEY_DELETEFILE": 146,
	"KEY_XFER": 147,
	"KEY_PROG1": 148,
	"KEY_PROG2": 149,
	"KEY_WWW": 150,
	"KEY_MSDOS": 151,
	"KEY_COFFEE": 152,
	"KEY_DIRECTION": 153,
	"KEY_CYCLEWINDOWS": 154,
	"KEY_MAIL": 155,
	"KEY_BOOKMARKS": 156,
	"KEY_COMPUTER": 157,
	"KEY_BACK": 158,
	"KEY_FORWARD": 159,
	"KEY_CLOSECD": 160,
	"KEY_EJECTCD": 161,
	"KEY_EJECTCLOSECD": 162,
	"KEY_NEXTSONG": 163,
	"KEY_PLAYPAUSE": 164,
	"KEY_PREVIOUSSONG": 165,
	"KEY_STOPCD": 166,
	"KEY_RECORD": 167,
	"KEY_REWIND": 168,
	"KEY_PHONE": 169,
	"KEY_ISO": 170,
	"KEY_CONFIG": 171,
	"KEY_HOMEPAGE": 172,
	"KEY_REFRESH": 173,
	"KEY_EXIT": 174,
	"KEY_MOVE": 175,
	"KEY_EDIT": 176,
	"KEY_SCROLLUP": 177,
	"KEY_SCROLLDOWN": 178,
	"KEY_KPLEFTPAREN": 179,
	"KEY_KPRIGHTPAREN": 180,
	"KEY_INTL1": 181,
	"KEY_INTL2": 182,
	"KEY_INTL3": 183,
	"KEY_INTL4": 184,
	"KEY_INTL5": 185,
	"KEY_INTL6": 186,
	"KEY_INTL7": 187,
	"KEY_INTL8": 188,
	"KEY_INTL9": 189,
	"KEY_LANG1": 190,
	"KEY_LANG2": 191,
	"KEY_LANG3": 192,
	"KEY_LANG4": 193,
	"KEY_LANG5": 194,
	"KEY_LANG6": 195,
	"KEY_LANG7": 196,
	"KEY_LANG8": 197,
	"KEY_LANG9": 198,
	"KEY_PLAYCD": 200,
	"KEY_PAUSECD": 201,
	"KEY_PROG3": 202,
	"KEY_PROG4": 203,
	"KEY_SUSPEND": 205,
	"KEY_CLOSE": 206,
	"KEY_PLAY": 207,
	"KEY_FASTFORWARD": 208,
	"KEY_BASSBOOST": 209,
	"KEY_PRINT": 210,
	"KEY_HP": 211,
	"KEY_CAMERA": 212,
	"KEY_SOUND": 213,
	"KEY_QUESTION": 214,
	"KEY_EMAIL": 215,
	"KEY_CHAT": 216,
	"KEY_SEARCH": 217,
	"KEY_CONNECT": 218,
	"KEY_FINANCE": 219,
	"KEY_SPORT": 220,
	"KEY_SHOP": 221,
	"KEY_ALTERASE": 222,
	"KEY_CANCEL": 223,
	"KEY_BRIGHTNESSDOWN": 224,
	"KEY_BRIGHTNESSUP": 225,
	"KEY_MEDIA": 226,
	"KEY_VMODE": 227,  # Deprecated, retained for backwards compatibility.
	"KEY_SWITCHVIDEOMODE": 227,
	"KEY_LAN": 238,
	"KEY_UNKNOWN": 240,
	"BTN_0": 256,
	"BTN_1": 257,
	"BtnA": 304,
	"BtnB": 305,
	"BtnC": 306,
	"BtnX": 307,
	"BtnY": 308,
	"BtnZ": 309,
	"BtnTL": 310,
	"BtnTR": 311,
	"BtnTL2": 312,
	"BtnTR2": 313,
	"BtnSelect": 314,
	"BtnStart": 315,
	"KEY_OK": 352,
	"KEY_SELECT": 353,
	"KEY_GOTO": 354,
	"KEY_CLEAR": 355,
	"KEY_POWER2": 356,
	"KEY_OPTION": 357,
	"KEY_INFO": 358,
	"KEY_TIME": 359,
	"KEY_VENDOR": 360,
	"KEY_ARCHIVE": 361,
	"KEY_PROGRAM": 362,
	"KEY_CHANNEL": 363,
	"KEY_FAVORITES": 364,
	"KEY_EPG": 365,
	"KEY_PVR": 366,
	"KEY_MHP": 367,
	"KEY_LANGUAGE": 368,
	"KEY_TITLE": 369,
	"KEY_SUBTITLE": 370,
	"KEY_ANGLE": 371,
	"KEY_ZOOM": 372,
	"KEY_MODE": 373,
	"KEY_KEYBOARD": 374,
	"KEY_SCREEN": 375,
	"KEY_PC": 376,
	"KEY_TV": 377,
	"KEY_TV2": 378,
	"KEY_VCR": 379,
	"KEY_VCR2": 380,
	"KEY_SAT": 381,
	"KEY_SAT2": 382,
	"KEY_CD": 383,
	"KEY_TAPE": 384,
	"KEY_RADIO": 385,
	"KEY_TUNER": 386,
	"KEY_PLAYER": 387,
	"KEY_TEXT": 388,
	"KEY_DVD": 389,
	"KEY_AUX": 390,
	"KEY_MP3": 391,
	"KEY_AUDIO": 392,
	"KEY_VIDEO": 393,
	"KEY_DIRECTORY": 394,
	"KEY_LIST": 395,
	"KEY_MEMO": 396,
	"KEY_CALENDAR": 397,
	"KEY_RED": 398,
	"KEY_GREEN": 399,
	"KEY_YELLOW": 400,
	"KEY_BLUE": 401,
	"KEY_CHANNELUP": 402,
	"KEY_CHANNELDOWN": 403,
	"KEY_FIRST": 404,
	"KEY_LAST": 405,
	"KEY_AB": 406,
	"KEY_NEXT": 407,
	"KEY_RESTART": 408,
	"KEY_SLOW": 409,
	"KEY_SHUFFLE": 410,
	"KEY_BREAK": 411,
	"KEY_PREVIOUS": 412,
	"KEY_DIGITS": 413,
	"KEY_TEEN": 414,
	"KEY_TWEN": 415,
	"KEY_CONTEXT_MENU": 438,
	"KEY_DEL_EOL": 448,
	"KEY_DEL_EOS": 449,
	"KEY_INS_LINE": 450,
	"KEY_DEL_LINE": 451,
	"KEY_ASCII": 510,
	"KEY_MAX": 511,
	"KEY_TOUCHPAD_TOGGLE": 530,
	"KEY_MOUSE": 530,
	"KEY_VOD": 627
}

KEYFLAGS = {
	0: "Make",
	1: "Break",
	2: "Repeat",
	3: "Long",
	4: "ASCII"
}

# First entry in each tuple is the preferred name.
#
knownAlisaes = {
	227: ("KEY_SWITCHVIDEOMODE", "KEY_VMODE"),
	530: ("KEY_MOUSE", "KEY_TOUCHPAD_TOGGLE")
}

def invertKeyIds():
	invKeyIds = {}
	for key, value in KEYIDS.items():
		if value not in invKeyIds:
			invKeyIds[value] = key
		else:
			if value in knownAlisaes and key in knownAlisaes[value]:
				invKeyIds[value] = knownAlisaes[value][0]
			else:
				print("[Keyids] Error: Key code %d is mapped to both '%s' and '%s'!" % (value, invKeyIds[value], key))
	return invKeyIds
